package com.hui.admin.controller;

import com.hui.admin.annotation.Log;
import com.hui.admin.common.result.Result;
import com.hui.admin.common.result.Results;
import com.hui.admin.dto.request.AuditPageRequestDTO;
import com.hui.admin.dto.request.AuditSaveRequestDTO;
import com.hui.admin.dto.response.AuditPageResponseDTO;
import com.hui.admin.service.AuditService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 审核控制层
 */
@RestController
@RequestMapping("/api/audit")
@RequiredArgsConstructor
public class AuditController {

    private final AuditService auditService;

    /**
     * 获取审核列表
     */
    @GetMapping
    public Result<AuditPageResponseDTO> getAuditList(AuditPageRequestDTO requestDTO) {
        return Results.success(auditService.getAuditList(requestDTO));
    }

    /**
     * 新增审核
     */
    @Log("新增审核")
    @PostMapping
    public Result<Void> createAudit(@RequestBody AuditSaveRequestDTO requestDTO) {
        auditService.createAudit(requestDTO);
        return Results.success();
    }

    /**
     * 删除审核
     */
    @Log("删除审核")
    @DeleteMapping("/{id}")
    public Result<Void> deleteAudit(@PathVariable("id") Long id) {
        auditService.deleteAudit(id);
        return Results.success();
    }

    /**
     * 批量删除
     */
    @Log("批量删除审核")
    @PostMapping("/deleteBatch")
    public Result<Void> deleteAudits(@RequestBody Map<String, Long[]> payload) {
        System.out.println("ids:" + Arrays.toString(payload.get("ids")));
        auditService.deleteAudits(payload.get("ids"));
        return Results.success();
    }

    /**
     * 修改审核
     */
    @Log("修改审核")
    @PutMapping
    public Result<Void> updateAudit(@RequestBody AuditSaveRequestDTO requestDTO) {
        auditService.updateAudit(requestDTO);
        return Results.success();
    }
}
